package com.qf.smartplatform.controller.advices;

import com.qf.smartplatform.dto.Result;
import com.qf.smartplatform.exceptions.MyBaseException;
import com.qf.smartplatform.exceptions.ResultCode;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * projectName:day12_27_Test
 * author:guoLei
 * time:2022/1/4 11:03
 * description:
 */
@ControllerAdvice
@Component
@ResponseBody
public class MyControllerAdvice {
    @ExceptionHandler(MyBaseException.class)
    public Result processMyBaseException(MyBaseException e){
        e.printStackTrace();
        int code=e.getCode();
        String message=e.getMessage();
        return Result.setError(code,message);
    }
    public Result processMyBaseException(Exception e){
        e.printStackTrace();
        return Result.setError(ResultCode.FAIL,"请检查您的网络",null);
    }
}
